/*
Program: DC-SAR, File dc-sar.c
Copyright (C) 2009 Davy De Coninck

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "conf.h"
#include "filefunc.h"
#include "printfunc.h"
#include "dc-sar.h"
#include "stringfunc.h"
#include "sql.h"
#include "string.h"

int main(int argc, char *argv[])
{
	print_out("DC-SAR-Importer  Copyright (C) 2009  Davy De Coninck");
	print_out("This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.");
	print_out("This is free software, and you are welcome to redistribute it");
	print_out("under certain conditions; type `show c' for details.");
	print_out("");
	print_out("Initializing...");
	print_out("Loading configuration...");

	if(file_exists("/etc/dc-sar.conf"))
	{
		print_out("Configuaration file found...");
		read_config_file(&Conf);
	} else {
		print_out("Configuaration not found (/etc/dc-sar.conf)...");
		print_out("Creating configuration file and exiting!");
		create_config_file();
		return 1;
	}

	print_out("Testing mysql connection...");
	if (connectiontest(&Conf) != 0){
		print_out("Connection failed! Exiting...");
		return 1;
	} else {
		print_out("Connection succeeded.");
	}

	//Connectie openen
	openconnection(&Conf);

	//Get db config params
	strcpy(Conf.lasttimestamp, Get_Value("lasttimestamp"));
	strcpy(Conf.logpath, Get_Value("logpath"));

	print_out("Start reading logfiles...");

	ProcessNonZipped(&Conf);

	closeconnection();

	return 0;
}
